package ribbon.consumer;

import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RandomRule;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.ribbon.RibbonClient;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;
import ribbon.consumer.selfrule.MyRule;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author:RenPu
 * @Date: 2020/8/23 9:44
 * @Version: 1.0
 * @description:
 */

//设置指定服务的的负载均衡，注解式的配置
@RibbonClient(name = "eureka-client", configuration = MyRule.class)
@SpringBootApplication
@EnableDiscoveryClient
public class RibbonConsumerMain {

    @Bean
    @LoadBalanced
    public RestTemplate get() {
        return new RestTemplate();
    }


//    //设置全局的负载均衡，代码式的配置
//    @Bean
//    public IRule defaultLBRule(){
//        return new RandomRule();
//    }


    public static void main(String[] args) {
        SpringApplication.run(RibbonConsumerMain.class, args);
    }


}
